#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    long long l, r;
    int op;
    vector<vector<int>> s(n, vector<int>(2, 0));
    for(int i = 0; i < n; ++i) {
        cin >> l >> r >> op;
        if(op == 1) {
            s[i][0] = l;
            s[i][1] = r;
        }else if(op == 2) {
            s[i][0] = l+1;
            s[i][1] = r-1;
        }else if(op == 3) {
            s[i][0] = l;
            s[i][1] = r-1;
        }else {
            s[i][0] = l+1;
            s[i][1] = r; 
        }
    }
    int res = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i+1; j < n; ++j) {
            if((s[i][1] <= s[j][1] && s[i][0] >= s[j][0])
            || (s[i][0] <= s[j][0] && s[i][1] >= s[j][1])
            || (s[i][0] <= s[j][0] && s[i][1] >= s[j][0])
            || (s[i][0] <= s[j][1] && s[i][1] >= s[j][1])) res++;
        }
    }
    cout << res << endl;
}